<%--
  Created by IntelliJ IDEA.
  User: LJJ
  Date: 2023/3/8
  Time: 17:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>添加仓库</title>


    <link href="css/all.css" rel="stylesheet" type="text/css">
    <link href="js/editor/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="js/editor/css/froala_editor.min.css" rel="stylesheet" type="text/css">
</head>

<body style="background-color: #e6ecf5">
<div class="book_con01">

    <h1 class="book_h01">添加仓库</h1>
    <p class="book_p" style="text-align: center">
        仓库名<span style="font-size: 15px; color: red;">*</span>：<input type="text" class="form-control" id="name"/>
    </p>
    <p class="book_p" style="text-align: center">
        地址<span style="font-size: 15px; color: red;">*</span>：<input type="text" class="form-control" id="address"/>
    </p>
    <p class="book_p" style="text-align: center">
        电话<span style="font-size: 15px; color: red;">*</span>：<input type="text" class="form-control" id="phone"
                                                                     onmouseout="hidePhoneError()"/>
        <br><span id="phoneError" hidden="hidden" style="font-size: 15px; color: red;">号码不规范</span>
    </p>
    <p class="book_p" style="text-align: center">
        密码<span style="font-size: 15px; color: red;">*</span>：<input type="password" class="form-control"
                                                                     id="password"/>
    </p>
    <p class="book_foot"><input type="button" value="添加" onclick="addWarehouse()"/></p>
</div>
<script src="js/jquery/jQuery-2.2.0.min.js"></script>
<script src="js/editor/js/froala_editor.min.js"></script>

<script src="js/editor/js/plugins/tables.min.js"></script>
<script src="js/editor/js/plugins/lists.min.js"></script>
<script src="js/editor/js/plugins/colors.min.js"></script>
<script src="js/editor/js/plugins/media_manager.min.js"></script>
<script src="js/editor/js/plugins/font_family.min.js"></script>
<script src="js/editor/js/plugins/font_size.min.js"></script>
<script src="js/editor/js/plugins/block_styles.min.js"></script>
<script src="js/editor/js/plugins/video.min.js"></script>
<script>
    function addWarehouse() {

        var count = 0
        var reg = /^[7]\d{6}/
        const name = $("#name")
        const address = $("#address")
        const phone = $("#phone")
        const password = $("#password")

        if (name.val() == "" || address.val() == "" || phone.val() == "" || password.val() == "") {
            count += 1
        }
        if (!reg.test(phone.val())) {
            count += 1
            $("#phoneError").show()
        }

        if (count > 0) {
            alert("请规范填写")
            return false
        }

        $.ajax({
            url: "addWarehouse.do",
            type: "post",
            data: {
                "name": $("#name").val(),
                "address": $("#address").val(),
                "phone": $("#phone").val(),
                "password": $("#password").val(),
            },
            dataType: "json",
            success: function (data) {
                alert(data.msg)
                if (data.code == 1) {
                    window.location.reload()
                }
            }
        })
    }

    function hidePhoneError() {
        $("#phoneError").hide()
    }
</script>
</body>
</html>